#include <iostream>
#include <cmath>
#include <string>
using namespace std;
//实现某一个功能有多种算法或者策略，我们可以根据环境或者条件的不同选择不同的算法或者策略来完成该功能
class CashSuper
{
public:
	//抽象类，收钱的纯虚函数
	virtual double acceptMoney(double money) = 0;
};

//正常收钱
class CashNormal :public CashSuper
{
public:

	double acceptMoney(double money) override
	{
		return money;
	}
};

//打折
class CashRebate :public CashSuper
{
private:
	double discount; //折扣
public:
	CashRebate(double discount)
	{
		this->discount = discount;
	}
	double acceptMoney(double money) override
	{
		return money * this->discount;
	}
};

class CashContext
{
private:
	CashSuper *cs;

public:
	//设置策略
	CashContext(string str)
	{
		if (str == "正常收费")
		{
			cs = new CashNormal();
		}
		else if (str == "打9折")
		{
			cs = new CashRebate(0.9);
		}
	}
	double getResult(double money)
	{
		return cs->acceptMoney(money);
	}
};

void main2()
{
	double money = 1000;
	CashContext *cc = new CashContext("正常收费");
	double result = cc->getResult(money);
	cout << result << endl;
	delete(cc);
	system("pause");
}